<div id="membersContainer" class="xxyydd medium-12 column" style="padding:0;">

	<?php foreach ($group_members as $value) { ?>
	
	<?php if(UserConnectionsTb::checkIfConnected($this->session->get('user_id'),$value->user_id)){ ?>
	
	<div class="hov medium-3  column">			
		<div class="text-right group_member medium-12 column" style="background:url(<?=IMAGE_URL_SMALL.$value->profile_pic?>);background-size:100% 100%;padding:0;">
		<div class="chnghov"></div>
		<a class="tiny button" style="padding:.5rem;">Connected</a>
			<div class="opacme text-center">
				<a><strong><?= $value->fname.' '.$value->lname ?></strong><i class="pri-set fa fa-lock"></i></a>
			</div>
		</div>	
	</div>
	<?php }else { ?>

		<?php if(!ConnectionRequestTb::findFirst(array(
				"conditions"=> "sender_id = ?0 and receiver_id = ?1",
				"bind" => array(0=>$this->session->get('user_id'),$value->user_id)
			))){ ?>
				<div class="hov medium-3  column">
					<div class="text-right group_member medium-12 column" style="background:url(<?=IMAGE_URL_SMALL.$value->profile_pic?>);background-size:100% 100%;padding:0;">
					<div class="chnghov"></div>
					<a friend-id = "<?=$value->user_id?>" class="tiny button btnConnect" style="padding:.5rem;">Connect</a>
						<div class="opacme text-center">
							<a><strong><?= $value->fname.' '.$value->lname ?></strong><i class="pri-set fa fa-lock"></i></a>
						</div>
					</div>	
				</div>
		<?php }else { ?>
				<div class="hov medium-3  column">
					<div class="text-right group_member medium-12 column" style="background:url(<?=IMAGE_URL_SMALL.$value->profile_pic?>);background-size:100% 100%;padding:0;">
					<div class="chnghov"></div>
					<a class="tiny button" style="padding:.5rem;">Requested</a>
						<div class="opacme text-center">
							<a><strong><?= $value->fname.' '.$value->lname ?></strong><i class="pri-set fa fa-lock"></i></a>
						</div>
					</div>	
				</div>
		<?php }?>
	<?php } //end of else?>
	<?php } // end of foreach ?>
	<div class="text-center medium-12 column" style="margin-top:1rem;">
				<a class="center tiny radius button">Show more</a>
	</div>
</div>


<script type="text/javascript">
	function insertRequest(friend_id)
	{
		var params = {};
		params.receiver_id = friend_id;
		return $.ajax({
			url: URL + 'connections/requestConnection',
			type: 'post',
			data: params,
			dataType: 'json'
		});
	}

	var $connect = $('.btnConnect');
	
	$connect.one('click',function(){
		
		var me = $(this);
		if(me.text() == "Connect" ){
			var friend_id = $(this).attr('friend-id');
			
			$(this).text('Sending . . .');
			
			insertRequest(friend_id).done(function(result){
				if(result.status == true)
				{

					me.text('Request Sent');
				}
				else
				{
					me.text(result.messages);
				}
			});
		}
	});

</script>